﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;
using System.Windows.Data;
using System.Collections.Generic;

namespace EIA.SLClient.Utility.Converters
{
    public class Bool2VisibilityConverter : GenericConverter<bool?, Visibility>
    {
        public Bool2VisibilityConverter()
            : base((s, p) =>
            {
                if (p != null && Consts.InversionTags.Contains(p.ToString().Trim().ToLower()))
                {
                    return s == true ? Visibility.Collapsed : Visibility.Visible;
                }
                else
                {
                    return s == true ? Visibility.Visible : Visibility.Collapsed;
                }
            }, (s, p) =>
            {
                if (p != null && Consts.InversionTags.Contains(p.ToString().Trim().ToLower()))
                {
                    return (s != Visibility.Visible);
                }
                else
                {
                    return (s == Visibility.Visible);
                }
            })
        {
        }
    }

    public class Visibility2BoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Visibility visibility = (Visibility)value;
            if (parameter != null && Consts.InversionTags.Contains(parameter.ToString().Trim().ToLower()))
            {
                return (visibility != Visibility.Visible);
            }
            else
            {
                return (visibility == Visibility.Visible);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null && Consts.InversionTags.Contains(parameter.ToString().Trim().ToLower()))
            {
                return (bool)value ? Visibility.Collapsed : Visibility.Visible;
            }
            else
            {
                return (bool)value ? Visibility.Visible : Visibility.Collapsed;
            }
        }
    }
}
